package com.cfc.stage1;

import org.junit.Test;

/**
 * @description:  excel 序号列表
 *   TODO
 *   https://leetcode.cn/problems/excel-sheet-column-number/description/
 * @author: yangxuan10
 * @create: 2024-05-16 14:47
 **/
public class ExcelSheetColumnNumber {

    @Test
    public void test1() {
        int a = 'A'; // A = 65
                     // Z = 65 + 26 = 91
                     // 65 - 26 = 39
        //A    = 1   =  26 0
        //AA   = 1*26 + 1
        //AAA  = 1*26*26 + 1*26 + 1

        //AZ   = 1*26 + 26
        //ZY   = 26*26 + 25
        //ZZ   = 26*26 + 26  = 702

        //AAA  = 1*26*26 + 1*26 + 1
        //AZZ  = 1*26*26 + 26*26 + 2
        //BAA  = 2*26*26 + 1*26 + 1
        //BBB  = 2*26*26 + 2*26 + 1

        //C    = 3
        //CC   = 3*26 + 3
        //CCC  = 4*26 + 3*26 + 2
        String columnTitle = "AB";
        char[] chars = columnTitle.toCharArray();
        int length = columnTitle.length();
        int sum = chars[length-1] - 64;
        for (int i = 1; i >= 1; i++) {
            int currentChar = chars[i];
            int currentReal = currentChar - 64;
            sum += (Math.pow(26,i) * currentReal);
        }
        System.out.println(sum);
    }

    @Test
    public void test2() {

        System.out.println((26 << 2));
    }

    public void excelSheetColumnNumber() {

    }

}